import ffi from 'ffi'
import ref from 'ref'

let libname = './libs/voice.dll'
let Library = ffi.Library(libname, {
  'speak': [ref.types.int, [ref.types.CString]]
})

/**
 * 语音合成
 * @param txt
 * @returns {Promise<any>}
 */
export function speak(txt) {
  return new Promise((resolve, reject) => {
    let ret = Library.speak(txt)
    if (ret === 0) {
      resolve(true)
    } else {
      reject(ret)
    }
  })
}
